#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    //.c -> exe -> load -> process -> 运行 -> 执行我们现在所写的代码
    printf("process is running...\n");
    pid_t id = fork();
    assert(id != -1);

    if(id == 0)
    {
        //child
        sleep(1);
        //load -> exe
        char * const argv_[] = 
        {
            "ls",
            "-a",
            "-l",
            "--color=auto",
            NULL
        };
        execvp("ls"/*要执行的程序在哪*/,argv_/*你想怎么执行*/);//所有的execl系列的接口,传参结束的时候以NULL结尾
        exit(1);
    }
    //parent
    int status = 0;
    pid_t ret = waitpid(id,&status,0);
    if(ret > 0) printf("wait success:exit_code:%d,sig:%d\n",(status>>8)&0xFF,status&0x7F);
    printf("process running done\n");
    return 0;
}

